home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Applications / ircle 1.5.1 / source / ircle sources / IRCNotify.p < prev    next >
Encoding:
Text File  |  1993-11-10  |  4.3 KB  |  208 lines  |  [TEXT/PJMM]

  1. {    ircle - Internet Relay Chat client    }
  2. {    File: IRCNotify    }
  3. {    Copyright © 1992 Olaf Titz (s_titz@ira.uka.de)    }
  4.  
  5. {    This program is free software; you can redistribute it and/or modify    }
  6. {    it under the terms of the GNU General Public License as published by    }
  7. {    the Free Software Foundation; either version 2 of the License, or    }
  8. {    (at your option) any later version.    }
  9.  
  10. {    This program is distributed in the hope that it will be useful,    }
  11. {    but WITHOUT ANY WARRANTY; without even the implied warranty of    }
  12. {    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    }
  13. {    GNU General Public License for more details.    }
  14.  
  15. {    You should have received a copy of the GNU General Public License    }
  16. {    along with this program; if not, write to the Free Software    }
  17. {    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    }
  18.  
  19. unit IRCNotify;
  20. { Deals with the /notify command }
  21.  
  22. interface
  23.  
  24. uses
  25.     TCPTypes, TCPStuff, TCPConnections,{}
  26.     Coroutines, ApplBase, MiscGlue, MsgWindows, InputLine, {}
  27.     IRCGlobals, IRCaux, IRCPreferences, IRCChannels;
  28.  
  29. procedure InitIRCNotify;
  30. { Startup }
  31.  
  32. procedure DoNotify (var s: string);
  33. { Processes the NOTIFY command }
  34.  
  35. procedure IsonReply (var s: string);
  36. { Processes ISON replies from server }
  37.  
  38. procedure OneNotify (var s: string; ison: boolean);
  39. { Processes explicit signon/off messages }
  40.  
  41. procedure GetNotifyList (var s: string);
  42. { Returns the notification list }
  43.  
  44. procedure RunNotify;
  45. { Does periodic queries }
  46.  
  47. implementation
  48.  
  49. var
  50.     doit, pending: boolean;
  51.     themap: set of byte;
  52.     noti: Handle;
  53.  
  54. procedure InitIRCNotify;
  55.     begin
  56.         doit := false;
  57.         pending := false;
  58.         themap := [];
  59.         noti := NewHandle(0);
  60.     end;
  61.  
  62. procedure RunNotify0;
  63.     var
  64.         s: string;
  65.         n: integer;
  66.     begin
  67.         if serverStatus = S_CONN then begin
  68.             n := GetHandleSize(noti);
  69.             BlockMove(noti^, @s[1], n);
  70.             s[0] := chr(n);
  71.             insert('ISON :', s, 1);
  72.             PutLine(s);
  73.         end;
  74.     end;
  75.  
  76. procedure GetNotifyList (var s: string);
  77.     var
  78.         i: integer;
  79.     begin
  80.         i := GetHandleSize(noti);
  81.         BlockMove(noti^, @s[1], i);
  82.         s[0] := chr(i);
  83.     end;
  84.  
  85. procedure DoNotify (var s: string);
  86.     var
  87.         i, n: integer;
  88.         j: byte;
  89.         olddoit: boolean;
  90.         p: string;
  91.     begin
  92.         if s = '' then begin
  93.             pending := false;
  94.             RunNotify0;
  95.         end;
  96.         while s <> '' do begin
  97.             NextArg(s, p);
  98.             insert(' ', p, 255);
  99.             if p[1] = '-' then begin
  100.                 n := length(p) - 1;
  101.                 i := Munger(noti, 0, @p[2], n, Ptr(1), 0);
  102.                 if i > 0 then begin
  103.                     for j := i to 255 - n do
  104.                         if j + n in themap then
  105.                             themap := themap + [j]
  106.                         else
  107.                             themap := themap - [j];
  108.                     for j := 255 - n + 1 to 255 do
  109.                         themap := themap - [j];
  110.                 end
  111.             end
  112.             else begin
  113.                 if length(p) + GetHandleSize(noti) < 250 then
  114.                     i := PtrAndHand(@p[1], noti, length(p));
  115.             end;
  116.         end;
  117.         pending := false;
  118.         i := GetHandleSize(noti);
  119.         olddoit := doit;
  120.         doit := (i > 0);
  121.         if doit then begin
  122.             GetNotifyList(s);
  123.             insert('*** Notify List: ', s, 1);
  124.             LineMsg(s);
  125.             if not olddoit then
  126.                 RunNotify;
  127.         end;
  128.     end;
  129.  
  130.  
  131. procedure onestring (i: integer; var s: string);
  132.     var
  133.         n: integer;
  134.         no: CharsHandle;
  135.     begin
  136.         n := GetHandleSize(noti);
  137.         if i > n then
  138.             s := ''
  139.         else begin
  140.             no := CharsHandle(noti);
  141.             BlockMove(@no^^[i], @s[1], n - i + 1);
  142.             s[0] := chr(n - i + 1);
  143.             i := pos(' ', s);
  144.             if i > 0 then
  145.                 s[0] := chr(i - 1);
  146.         end;
  147.     end;
  148.  
  149.  
  150. procedure OneNotify (var s: string; ison: boolean);
  151.     var
  152.         i: integer;
  153.     begin
  154.         i := Munger(noti, 0, @s[1], length(s), nil, 0);
  155.         if i >= 0 then begin
  156.             if ison then
  157.                 themap := themap + [i]
  158.             else
  159.                 themap := themap - [i];
  160.         end;
  161.     end;
  162.  
  163.  
  164. procedure IsonReply (var s: string);
  165.     var
  166.         p: string;
  167.         i: integer;
  168.         j: byte;
  169.         newmap: set of byte;
  170.     begin
  171.         if pending then begin
  172.             newmap := [];
  173.             while s <> '' do begin
  174.                 NextArg(s, p);
  175.                 i := Munger(noti, 0, @p[1], length(p), nil, 0);
  176.                 if i >= 0 then
  177.                     newmap := newmap + [i];
  178.             end;
  179.             for j := 0 to 255 do
  180.                 if (j in themap) and (not (j in newmap)) then begin
  181.                     onestring(j, p);
  182.                     insert('*** Signoff: ', p, 1);
  183.                     Message(p);
  184.                 end
  185.                 else if (not (j in themap)) and (j in newmap) then begin
  186.                     onestring(j, p);
  187.                     insert('*** Signon: ', p, 1);
  188.                     Message(p);
  189.                 end;
  190.             themap := newmap;
  191.             pending := false
  192.         end
  193.         else begin
  194.             insert('*** Signed on: ', s, 1);
  195.             LineMsg(s)
  196.         end
  197.     end;
  198.  
  199.  
  200. procedure RunNotify; { Does periodic queries }
  201.     begin
  202.         if doit and (not pending) then begin
  203.             pending := true;
  204.             RunNotify0
  205.         end
  206.     end;
  207.  
  208. end.